import java.io.StringReader;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

class <tablename>INSERT {
    public String getSQLStatement(String xmlData) throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(false);
        dbf.setValidating(false);

        DocumentBuilder builder = dbf.newDocumentBuilder();
        Document document = builder.parse(new InputSource(new StringReader(xmlData)));
        document.normalizeDocument();

        NodeList data = document.getElementsByTagName("data");
        NodeList children = data.item(0).getChildNodes();

        NodeList tableSchemaNl = document.getElementsByTagName("schema-name");
        String schemaName = tableSchemaNl.item(0).getTextContent();

        NodeList tableNameNl = document.getElementsByTagName("table-name");
        String tableName = tableNameNl.item(0).getTextContent();

        StringBuffer sb = new StringBuffer("INSERT INTO ");
        sb.append(schemaName);
        sb.append(".");
        sb.append(tableName);
        sb.append(" SET ");

        for(int i=0; i<children.getLength(); i++){
            Element elem = (Element) children.item(i);
            String nodeName = elem.getNodeName();
            String nodeContent = elem.getTextContent();

            if (!"schema-name".equals(nodeName) && !"table-name".equals(nodeName)
                    && !"primary-key".equals(nodeName) && !"foreign-key".equals(nodeName)) {
                String autoIncr = elem.getAttribute("autoincr");
                if ("false".equals(autoIncr)) {
                    if (nodeContent.contains("'")) {
                        nodeContent=nodeContent.replace("'","\\'");
                    }
                    sb.append(nodeName);
                    sb.append(" = '");
                    sb.append(nodeContent);
                    if (i!=children.getLength()-1) {
                        sb.append("',");
                    } else {
                        sb.append("'");
                    }
                }
            }
        }

        return sb.toString();
    }
}